﻿  #include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowTitle(QStringLiteral("Qt使用鍵盘钩子Hook(支持判断按下、弹起、自动)"));

#ifdef Q_OS_WIN
    m_pHook = new Hook();
    m_pHook->installHook();
    m_pHook->SetKeyboardCall(std::bind(&MainWindow::UpdateCapslockTip, this, std::placeholders::_1,std::placeholders::_2,std::placeholders::_3));
#endif
}

MainWindow::~MainWindow()
{
    m_pHook->unInstallHook();
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    ui->textEdit->clear();
}

void MainWindow::UpdateCapslockTip(int keyCode, bool downOrUp, bool aotu)
{
    QString s = "key pressed:--------:%1  downOrUp:%2  aotu:%3";
    s = s.arg(keyCode).arg(downOrUp).arg(aotu);
    ui->textEdit->append(s);
    qDebug() << "key pressed:--------:" << keyCode
             << "downOrUp:" << downOrUp
             << "aotu:" << aotu;
}
